<?php
set_time_limit ( 0 );
include_once '../connect.php';

$sql = "SELECT id,url FROM fangjia where id >= 123350";
$result = mysql_query ( $sql, $dbc ) or die ( mysql_error () );

$Reg_City = "/<span class=\"city\">(.*)<\/span><span class=\"city_icon\">选择城市/Us";
$Reg_Location = "/小区房价<\/a>(.*)href=\"(.*)\">(.*)<\/a>(.*)href=\"(.*)\">(.*)<\/a>(.*)href=\"(.*)\">(.*)<\/a>/Us";
$Reg_Xiaoqu_Location = "/小区地址：(.*) /Us";
$Reg_jungong = "/竣工时间：(.*)<\/li>/U"; 
$Reg_Shoujia = "/<big>(.*)<\/big>元\/平米/Us";
$Reg_zufang_url = "/<li ><a href=\"(.*)\" style=\"_height:auto;_overflow:auto\"(.*)租 房/U";

while ( $arr_xiaoqu = mysql_fetch_array ( $result ) ) {
	$fcontents = file_get_contents ( $arr_xiaoqu[url] );
	
	preg_match_all ( $Reg_City, $fcontents, $Arr_City ); //$Arr_City[1][0] 是城市
	$city = $Arr_City[1][0];
	
	preg_match_all ( $Reg_Location, $fcontents, $Arr_Location );//$Arr_Location[3][0]是区，[6][0]是地块，[9][0]是小区名
	$qu = $Arr_Location[3][0];
	$dikuai = $Arr_Location[6][0];
	$xiaoqu = $Arr_Location[9][0];
	
	preg_match_all ( $Reg_Xiaoqu_Location, $fcontents, $Arr_Xiaoqu );//$Arr_Xiaoqu[1][0]是小区地址
	$xiaoqudizhi = $Arr_Xiaoqu[1][0];
	
	preg_match_all ( $Reg_jungong, $fcontents, $Arr_jungong );//$Arr_jungong[1][0]是竣工日期
	$jungong = $Arr_jungong[1][0];
	
	preg_match_all ( $Reg_Shoujia, $fcontents, $Arr_Shoujia );//$Arr_Shoujia[1][0]是售价
	$shoujia = $Arr_Shoujia[1][0];
	
	preg_match_all ( $Reg_zufang_url, $fcontents, $Arr_zufang_url );//$Arr_zufang_url[1][0]是租房URL
	$rent_url = $Arr_zufang_url[1][0];
	
	$query = "UPDATE fangjia SET xiaoqu = '$xiaoqu',chengshi = '$city',qu = '$qu'
	, dikuai = '$dikuai', dizhi = '$xiaoqudizhi', jungongriqi = '$jungong', 
	shoujia = '$shoujia', zufang_url = '$rent_url' WHERE id = '$arr_xiaoqu[id]'" ;

	$result_xiaoqu = mysql_query ( $query, $dbc ) or die ( mysql_error () );
	
	
}
echo "写完了什么的！";
?>